package com.hh.demo_ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

import com.hh.adapters.CDTListAdapter;
import com.hh.clientdatatable.ClientDataTable;
import com.hh.clientdatatable.TCell.ValueType;
import com.hh.clientdatatable.TColumn;
import com.hh.ui.widget.UiHorizontalListView;

public class Sample_HorizontalListView extends Activity implements OnItemClickListener {

	private ClientDataTable _mCDT;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sample_horizontal_listview);

		createCDT();
		fillCDT();
		CDTListAdapter lAdapter=new CDTListAdapter(this, R.layout.row_horizontal_item, _mCDT);
		/*
		 * Default horizontal listView
		 */
		UiHorizontalListView lListH=(UiHorizontalListView) findViewById(R.id.SH_listView);	

		lListH.setAdapter(lAdapter);
		
		lListH.setOnItemClickListener(this);
		/**
		 * To customize H LV , THEY MUST BE after the setAdapter
		 * 
		 */
		
		/*
		lListH.setBackgroundColor(Color.YELLOW);
		lListH.setItemBackgroundColor(Color.GRAY);
		lListH.setDividerColor(Color.RED);
		lListH.setItemSpacing(30);
		 */
	}

	private void createCDT(){

		_mCDT=new ClientDataTable(this);
		_mCDT.addColumn(new TColumn("Item", ValueType.TEXT));
		_mCDT.addColumn(new TColumn("Image", ValueType.INTEGER));
	}


	private void fillCDT(){

		String[] lItemsTab=getResources().getStringArray(R.array.ArrayHorizontalItems);
		int[] lItemsImage={R.drawable.ic_chrome,R.drawable.ic_facebook,R.drawable.ic_firefox,
				R.drawable.ic_googleplus,R.drawable.ic_internet,R.drawable.ic_maps,R.drawable.ic_message,R.drawable.ic_meto,
				R.drawable.ic_plaris,R.drawable.ic_skype,R.drawable.ic_tweeter};

		for (int i = 0; i < lItemsImage.length; i++) {
			
			_mCDT.append();
			_mCDT.cellByName("Item").setValue(lItemsTab[i]);
			_mCDT.cellByName("Image").setValue(lItemsImage[i]);
			_mCDT.commit();
		}
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
		
		_mCDT.moveToPosition(position);
		String lItem=_mCDT.cellByName("Item").asString();
		
		Toast.makeText(this, "Clicked Item : "+lItem, Toast.LENGTH_SHORT).show();
	}
}
